<script type="text/ecmascript-6">
  import Navbar from '../../components/base/navbar.vue';
  export default{
    name:"user_my_activity",
    components:{
      Navbar
    },
    data(){
        return {
            tabList:[
              {
                id:0,
                name:"全部",
                page: 0,
                hasMore: true,
                init: false,
                isList:false
              },
              {
                id:1,
                name:"未开始",
                page: 0,
                hasMore: true,
                init: false,
                isList:false
              },
              {
                id:2,
                name:"进行中",
                page: 0,
                hasMore: true,
                init: false,
                isList:false
              },
              {
                id:3,
                name:"已结束",
                page: 0,
                hasMore: true,
                init: false,
                isList:false
              },
              {
                id:4,
                name:"已取消",
                page: 0,
                hasMore: true,
                init: false,
                isList:false
              }
            ],
            dataList:{

            },
            tabIndex:0,
            isList:false,
            isDrag:false,
            heights:"100%"
        }
    },
     methods:{
        refresh(){
            this.$store.dispatch('queryMyActivity',{index:this.tabIndex});
        },
        loadMore(){

            var page=this.tabList[this.tabIndex].page + 1;
            this.$store.dispatch('queryMyActivity',{index:this.tabIndex,page:page});
        },
        jump(page,id){
            this.$router.push({name:page,params:{id:id} });
        },
         myActivityList(res,index){
             let list,
                 page =res.meta.pagination,
                 current_page =page.current_page,
                 total_pages =page.total_pages;
             if( current_page ==1){
                 list =res.data;
             }
             else{
                 list =this.dataList[index].concat(res.data);
             }
            this.tabIndex=index;
            this.$set(this.dataList,index,list);
            this.tabList[index].init = true;
            this.tabList[index].page = current_page;
            this.tabList[index].hasMore = current_page < total_pages;
            if(list.length ==0){
                this.isList =true;
            }else{
                this.isList=false;
            }
            this.$emit("done");
//           this.$refs.pulldown[this.tabIndex].onLoadOff();
         },
         change(i){
           this.tabIndex=i;
           this.$router.replace({name: 'my_activity', params: {index: this.tabIndex}});
           if(!this.tabList[i].init){
             this.$store.dispatch('queryMyActivity',{index:this.tabIndex})
           }
           else{
             this.isList=!!!this.dataList[i].length;
           }
         },
         done(){
           this.$nextTick(() => {
             this.$refs.pulldown[this.tabIndex].onLoadOff();
           })
         }
     },
    created(){
        EventBus.$on("my-activityList",this.myActivityList);
        this.$on("done",this.done);
    },
     beforeDestory(){
        EventBus.$off("my-activityList");
     },
     mounted(){
       this.tabIndex = Number(this.$route.params.index) || 0;
       this.$store.dispatch("queryMyActivity",{index:this.tabIndex});
     }
  }
</script>
